package com.think.teaching.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.think.common.utils.Common;
import com.think.teaching.mapper.SchoolMapper;
import com.think.teaching.model.College;
import com.think.teaching.model.School;

@Service
public class SchoolServiceImpl extends BaseServiceImpl<SchoolMapper, School> {

	
	public School UpdateSchool(School data) {
		data.setUpdatedBy(Common.GetCurrentAuthor().getUserId());
		if (updateById(data)) {
			return data;
		}
		else {
			return null;
		}
	}
	
	public School getSchoolWithName(String name){
		QueryWrapper<School> queryWrapper = new QueryWrapper<School>();
		queryWrapper.ne("delflag", 1);
		queryWrapper.like("name", name);
		return getOne(queryWrapper);
	}
	
	public List<School> SearchSchoolWithKey(String key,Boolean withoutBan){
		QueryWrapper<School> queryWrapper = new QueryWrapper<School>();
		queryWrapper.ne("delflag", 1);
		if (withoutBan) {
			queryWrapper.eq("state", 1);
		}
		queryWrapper.like("name", key);
		return list(queryWrapper);
	}
	
	public List<College> getSchoolColleges(Integer schooId){
		return baseMapper.selectSchoolColleges(schooId);
	}
	
	public IPage<School> ListSchoolWithTagAndType(Integer count,Integer page,Boolean withoutBan){
		QueryWrapper<School> queryWrapper = new QueryWrapper<School>();
		queryWrapper.ne("delflag", 1);
		if (withoutBan) {
			queryWrapper.eq("state", 1);
		}
		IPage<School> iPage = new Page<School>(page,count);
		return page(iPage, queryWrapper);
	}
}
